<template>
  <div class="application-list">
    <el-card>
      <div slot="header">
        <search-bar @link="linkCluster"></search-bar>
      </div>
      <div class="app-list">
        <el-table :data="appList" style="width: 100%">
          <el-table-column prop="name" label="名称"> </el-table-column>
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              <div>
                <el-tag type="success" v-if="scope.row.status == 1"
                  >已连接</el-tag
                >
                <el-tag type="danger" v-else>已断开</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template>
              <div>
                <el-button type="primary" size="mini">编辑</el-button>
                <el-button size="mini">断开</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <!-- 链接已有集群 弹窗 -->
    <el-dialog
      title="链接已有集群"
      :visible.sync="dialogVisible"
      width="45%"
      :close-on-click-modal="false"
      @close="closeDialog"
    >
      <el-form :model="form" label-width="100px" :rules="rules" ref="ruleForm">
        <el-form-item label="名称" prop="cluster_name">
          <el-input
            v-model="form.cluster_name"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="desc">
          <el-input v-model="form.desc" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="Kubeconfig" prop="config">
          <div class="upload-cont">
            <el-upload
              action="https://jsonplaceholder.typicode.com/posts/"
              :limit="1"
              :file-list="fileList"
              :on-change="handleChange"
              :on-remove="handleRemove"
            >
              <div v-if="fileList.length < 1" class="upload-style">
                <i class="el-icon-upload"></i> 上传配置文件
              </div>
            </el-upload>
            <i class="el-icon-question q-icon"></i>
          </div>
        </el-form-item>
        <div class="config-style">
          <el-input
            type="textarea"
            :autosize="{ minRows: 15, maxRows: 15 }"
            resize="none"
            v-model="form.config"
          ></el-input>
        </div>
      </el-form>
      <div slot="footer">
        <el-button size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import SearchBar from "./components/SearchBar.vue";
export default {
  components: { SearchBar },
  data() {
    return {
      appList: [
        {
          id: 1,
          name: "微擎系统v2.0",
          logo: "",
          status: "0",
          desc:
            "集群是一组相互独立的、通过高速计算机网络互联的计算机，它们构成了一个组，并以单一系统的模式加以管理。",
        },
        {
          id: 2,
          name: "微擎系统v3.0",
          logo: "",
          status: "0",
          desc:
            "集群是一组相互独立的、通过高速计算机网络互联的计算机，它们构成了一个组，并以单一系统的模式加以管理。",
        },
        {
          id: 3,
          name: "微擎电子合同v1.0",
          logo: "",
          status: "1",
          desc:
            "集群是一组相互独立的、通过高速计算机网络互联的计算机，它们构成了一个组，并以单一系统的模式加以管理。",
        },
        {
          id: 4,
          name: "微擎电子合同v2.0",
          logo: "",
          status: "0",
          desc:
            "集群是一组相互独立的、通过高速计算机网络互联的计算机，它们构成了一个组，并以单一系统的模式加以管理。",
        },
        {
          id: 5,
          name: "微擎电子合同v3.0",
          logo: "",
          status: "1",
          desc:
            "集群是一组相互独立的、通过高速计算机网络互联的计算机，它们构成了一个组，并以单一系统的模式加以管理。",
        },
        {
          id: 6,
          name: "微擎系统v2.0",
          logo: "",
          status: "0",
          desc:
            "集群是一组相互独立的、通过高速计算机网络互联的计算机，它们构成了一个组，并以单一系统的模式加以管理。",
        },
      ],
      dialogVisible: false,
      form: {
        cluster_name: "",
        desc: "",
        config: "",
      },
      fileList: [],
      rules: {
        cluster_name: [
          { required: true, message: "请输入内容", trigger: "blur" },
        ],
        config: [
          { required: true, message: "请上传配置文件", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    handleRemove() {
      this.fileList = [];
    },
    handleChange(file, fileList) {
      console.log(file, fileList);
      this.fileList = [file];
    },
    linkCluster() {
      this.dialogVisible = true;
    },
    closeDialog() {
      this.$refs.ruleForm.resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
@import "index.scss";
</style>
